<template>
    <rx-dialog @handOk="submitForm" @cancel="closeWindow" :canceltext="$ti18('rxForm.closeBtn','关闭')">
      <a-form style="padding: 10px;">
        <a-form-item :label="i18n('sign.personSign','加签人员')" :label-col="labelCol" :wrapper-col="wrapperCol">
          <rx-text-list
            v-model="signUsers"
            :textfield="'fullName'"
            :valfield="'userId'"
            @click="selectUsers"
            style="margin-top: 5px;"
          >
            <a-icon type="user"></a-icon>
          </rx-text-list>

        </a-form-item>
        <a-form-item :label="i18n('sign.opinion','意见')" :label-col="labelCol" :wrapper-col="wrapperCol">
          <a-textarea v-model="opinion" style="width: 100%"/>
        </a-form-item>
      </a-form>

    </rx-dialog>
</template>

<script>
    import {Dialog,Util,RxTextList,RxDialog} from '@lowcode/jpaas-common-lib';
    import BpmtaskApi from "@/api/bpm/core/bpmTask";
    export default {
        name: "BpmTaskAddSign",
        props:{
            taskId:{//流程任务Id
                type:String,
                required:true
            },
            layerid: String,
            lydata: Object,
            destroy:Function
        },
        comments:{
          RxTextList,
            RxDialog
        },
        data (){
            return {
                labelCol: { span: 4 },
                wrapperCol: { span: 8 },
                opinion:'',

                msgTypes:[],
                signUsers:[],
                signUsersObj:"",
                rxtext:[
                  {value:'aaa',text:'A'},
                  {value:'bbb',text:'b'}
                ]
            }
        },
        methods:{
            i18n(name,text,key){
                return this.$ti18(name,text,"bpmTask",key);
            },
            selectUsers(){
                let self=this;
                Dialog.openUserDialog({
                    curVm: this,data:{single:false,initUsers: self.signUsers}, widthHeight: ['800px', '600px']
                },function(self,data){
                    var ary=[];
                    for(let i=0;i<data.length;i++){
                        ary.push({userId:data[i].userId,fullName:data[i].fullName});
                    }
                    self.signUsers = ary
                })
            },
            closeUser(userId){
                for(let i=0;i<this.signUsers.length;i++){
                    if(this.signUsers[i].userId==userId){
                        this.signUsers.splice(i,1);
                        return;
                    }
                }
            },
            closeWindow(){
                Util.closeWindow(this,'cancel');
            },
            submitForm(e){
                if(this.signUsers.length == 0 || this.opinion==''){
                    e.loading=false;
                    this.$message.error(this.i18n('sign.selectUserTips','请选择用户与填写意见！'));
                    return ;
                }
                var userIds=[];
                this.signUsers.forEach(item=>{
                    userIds.push(item.userId);
                });

                BpmtaskApi.addSignUser({
                    taskId:this.taskId,
                    toUserIds:userIds.join(','),
                    opinion: this.opinion
                }).then(resp=>{
                    Util.closeWindow(this,'ok');
                });
            }
        }
    }
</script>

<style scoped>

</style>